package com.bdqn.ch02.sl;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

public class pubDate {
    Document doc=null;
    public void getDocument(){
        //得到DOM解析器的工厂实列
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        //获取解析器工厂
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            //解析XML文档，得到一个Document，即DOM树
             doc= db.parse("src/dao/PhoneInfo2.xml");

        } catch (ParserConfigurationException e) {
            e.fillInStackTrace();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (SAXException e) {
            throw new RuntimeException(e);
        }
    }
    public void showInfo(){
        //读取新闻
        NodeList list =doc.getElementsByTagName("pudbate");
        Element pubDateElement =(Element)list.item(0);
        //读取文本节点
        String pubDate=pubDateElement.getTextContent();
        System.out.println(pubDate);
    }

    public static void main(String[] args) {
        pubDate Parse=new pubDate();
        Parse.getDocument();
        Parse.showInfo();
    }
}
